package cn.edu.yzu.scholarship.model;

import com.jfinal.ext.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

public class College extends Model<College>{
	
	private static final long serialVersionUID = -1317156849066589185L;
	
	public static final College dao = new College();
	
	/**学院合并**/
	public static void mergeCollege(String oldIds, String lqyxsmc) {
		String lqyxsm = Db.findFirst(SqlKit.sql("college.findNextLqyxsm")).get("lqyxsm");//得到新的学院代码
		Db.update(SqlKit.sql("college.insert"),lqyxsm,lqyxsmc);//插入新的学院信息
		for(String oid : oldIds.split(",")) {//删除原学院信息并更新库中学生、发放等表中的学院信息
			Db.update(SqlKit.sql("college.delete"),oid);
			Db.update(SqlKit.sql("grant.mergeCollege"),lqyxsm, lqyxsmc, oid);
			Db.update(SqlKit.sql("major.mergeCollege"),lqyxsm, lqyxsmc, oid);
			Db.update(SqlKit.sql("student.mergeCollege"),lqyxsm, lqyxsmc, oid);
		}
	}
}
